package com.smart.car.member.controller;

import com.smart.car.common.res.bean.ResponseResult;
import com.smart.car.common.res.exception.BusinessException;
import com.smart.car.member.entity.MemberCard;
import com.smart.car.member.service.MemberCardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TODO 会员卡控制
 * @author: zoutao
 * @date: 2021/4/15
 */
@Api(tags = "会员卡模块")
@Slf4j
@RestController
@RequestMapping("/card")
public class MemberCardController {

    @Autowired
    private MemberCardService memberCardService;

    /**
     * TODO 查询所有会员卡
     * @author zoutao.blog.csdn.net
     */
    @ApiOperation(value = "查询所有会员卡")
    @GetMapping("/list")
    public List<MemberCard> list() {
        List<MemberCard> members = memberCardService.list();
        log.info("查询会员卡列表：{} " ,members);
        return members;
    }

    /**
     * TODO 新增开会员
     * @param json
     * @return
     */
    @PostMapping(value = "/add")
    public ResponseResult<Integer> addMonthCard(String json) throws BusinessException {
        ResponseResult<Integer> result = new ResponseResult<>();
        int rtn = memberCardService.addMonthCard(json);
        log.debug("开通月度会员成功：" + json);
        result.setData(rtn);
        return result;
    }

    /**
     * TODO 是否是会员？
     * @param vehicleNo
     * @return
     */
    @PostMapping(value = "isMonthCardUser")
    public ResponseResult<Boolean> isMonthCardUser(String vehicleNo) throws BusinessException{
        ResponseResult<Boolean> result = new ResponseResult<>();
        boolean flag = memberCardService.isMonthCardUser(vehicleNo);
        result.setData(flag);
        return result;
    }


}